import { reqCategoryList, reqGetBannerList, reqFloorList } from '@/api/index.js'
//home组件的小仓库
const state = { categoryList:[],bannerList:[],floorList:[]};
//发送异步axios请求
const actions = {
   async categoryLists({ commit }) {
         let result=await reqCategoryList();
        if (result.code == 200) {
            commit("categoryLists",result.data)
        }
    },//调用此函数getBannerList获取mock模拟轮播图数据
    async getBannerList({ commit }) {
        //解构赋值
        let result = await reqGetBannerList();
        if (result.code == 200) {
            commit('getBannerList', result.data);
        }
    },
    async getFloorList({ commit }) {
        let result = await reqFloorList();//异步函数
        if (result.code == 200) {
            commit('getFloorList',result.data)
        }
    }
};
const mutations = {
    categoryLists(state, data) {
        state.categoryList = data;
        console.log("获取导航栏信息成功");
    },
    getBannerList(state,data) {
        state.bannerList = data;
    },
    getFloorList(state,data) {
        state.floorList = data;
        console.log("获取底部信息成功");
    }
};
const getters = {};
export default {
    state,
    actions,
    mutations,
    getters
}